package com.xishu.controller;

import com.xishu.annotation.valid.Admin;
import com.xishu.annotation.valid.MethodValidator;
import com.xishu.dao.jpa.OrderDao;
import com.xishu.entity.order.Order;
import com.xishu.response.ResponseData;
import com.xishu.service.CommonService;
import com.xishu.util.BeanUtil;
import com.xishu.util.Tools;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
public class TestController implements Tools {
    private CommonService commonService = CommonService.getInstance();

    @ApiOperation(value = "测试类接口")
    @MethodValidator(mustLogin = false)
    @PutMapping(value = ("/test/order"), produces = ("application/json;charset=UTF-8"))
    @Admin
    public ResponseData test(@RequestBody Order order) throws Exception {
        OrderDao orderDao = BeanUtil.getBean(OrderDao.class);
        List<Order> orderList = orderDao.findTimeOrder(31l, order.getStartCreateTime(), System.currentTimeMillis(), true, true, false);
        orderList = orderList.stream().filter(p -> getBoolean(p.getExpiredOrder())).collect(Collectors.toList());
        return commonService.createResponse(orderList);
    }
}
